package net.web.milkteapos.bean;

import java.util.Date;
import java.util.List;

import net.web.milkteapos.module.SaleModule;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.ManyMany;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.Table;

/**
 * 订单
 */
@Table("sale")
public class Sale {

	@Id
	@Column("order_id")
	private int orderId;
	@Column("order_date")
	private Date orderDate;
	@Column("product_sum")
	private int productSum;
	@Column("total_amount_id")
	private int totalAmountId;
	@Column("customer_pay_id")
	private int customerPayId;
	@Column("employee_id")
	private int employeeId;
	@Column("is_pay")
	private boolean isPay;
    private int num;
	public void setPay(boolean isPay) {
		this.isPay = isPay;
	}

	@ManyMany(target = Product.class, relation ="sale_list", from="order_id", to="product_id" )
	private List<Product> products;

	@One(target = Money.class, field = "totalAmountId")
	private Money totalAmount;
	
	@One(target = Money.class, field = "customerPayId")
	private Money customerPay;
	
	@One(target = Employee.class, field = "employeeId")
	private Employee employee;
	
	public Sale() {
		this.isPay = false;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	
	public int getProductSum() {
		return productSum;
	}

	public void setProductSum(int productSum) {
		this.productSum = productSum;
	}

	public int getTotalAmountId() {
		return totalAmountId;
	}

	public void setTotalAmountId(int totalAmountId) {
		this.totalAmountId = totalAmountId;
	}

	public int getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(int employeeId) {
		this.employeeId = employeeId;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public Money getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(Money totalAmount) {
		this.totalAmount = totalAmount;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
	
	public int getCustomerPayId() {
		return customerPayId;
	}

	public void setCustomerPayId(int customerPayId) {
		this.customerPayId = customerPayId;
	}

	public boolean isPay() {
		return isPay;
	}

	public Money getCustomerPay() {
		return customerPay;
	}

	public void setCustomerPay(Money customerPay) {
		this.customerPay = customerPay;
	}
	
	public int getNum(){
		return num;
	}

	public void setNum(int num){
		this.num = num;
	}
	public void summary() {
		if(products != null && products.size() > 0) {
			totalAmount = new Money();
			productSum = products.size();
			for (Product product : products) {
				totalAmount.add(product.getMoney());
			}
		}
	}
}
